package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    private DVD dvd;
    private Copy copy;
    
    public DvdUI()
    {
        dvdCtr = new DVDCtr();
    }
    
    public void start()
    {
        dvdMenu();
        dvdCtr = new DVDCtr();
    }
    
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise = writeDVDMenu();
            if (choise == 1)
            {
                findDVD();
            }
            else{if(choise == 2){
                   addDVD();
                }
                else{
                    if(choise == 3){
                        addCopy();
                    }
                    else{
                        if(choise == 4){
                             deleteDVD();
                        }
                        else{
                            if(choise == 5){
                                listAllDvds();
                            }
                            else{
                                exit = true;
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else
            
        }//end while
    }
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println(" *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Create DVD specimen");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choice: ");
            
            int choise = keyboard.nextInt();
            return choise;
    }
    private int inputDVDid()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD number: ");
        int id = keyboard.nextInt();
        return id;
    }
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
        private String inputDirector()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Director: " );
        String director = keyboard.nextLine();
        return director;
    }
        private int inputYear()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type year of release: ");
        int year = keyboard.nextInt();
        return year;
    }
    
        public void showId(long id)
    {
        System.out.println("DVDs ID: " + id);
    }
    public void showTitle(String title)
    { 
        System.out.println("Title of the DVD: " + title);
    }
    public void showDirector(String director)
    { 
        System.out.println("Name of the Director: " + director);
    }
            public void showYear(long year)
    {
        System.out.println("DVDs year of release: " + year);
    }
    
    private void getDVD()
    {
        String title = inputTitle();
        ArrayList<DVD> dvds = dvdCtr.dvdsNo();
        DVD dvd = dvdCtr.findDVD(title);
        System.out.println("\n" + dvd.getId() + " " + dvd.getTitle() + " " + dvd.getDirector() + " " + dvd.getYear() + "\n");
        
        if(dvd == null)
        {
            System.out.println("Can not find DVD");
        }
    }
    
    //there is need for more methods to read information about DVDs
    //and methods to display the information
  
    private void findDVD()
    {     
        int id = inputDVDid();
        //is to be changed when the DVD controller is completed
    }
    private void addDVD()
    {
        int id = inputDVDid();
        String title = inputTitle();
        String director = inputDirector();
        int year = inputYear();
        
        dvdCtr.addDVD(id, title, director, year);
    }
    private void addCopy()
    {
        
    }
    private void deleteDVD()
    {
         ArrayList<DVD> dvds = dvdCtr.dvdsNo();
         int index = 0;
         for(DVD dvd : dvds)
         {
               System.out.println("\n" + "index number :" + index + " " + dvd.getId() + " " + dvd.getTitle() + " " + dvd.getDirector() + " " + dvd.getYear());
               index ++;
         }
         
//          System.out.println("Type the index number you want to delete");
//          long id = inputIndexNo();
         
//          dvdCtr.deleteDVD(id);
         System.out.println("DVD is no longer registered on your list");
    }
    
    private void listAllDvds()
    {
        ArrayList<DVD> dvds = dvdCtr.dvdsNo();
        int index = 0;
        for(DVD dvd : dvds)
        {
            System.out.println(index + " " + dvd.getId() + " " + dvd.getTitle() + " " + dvd.getDirector() + " " + dvd.getYear());
            index ++;
        }
        
        System.out.println();
    }
}